/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80 filetype=javascript: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

/**
 * This component replaces original IEProfileMigrator with bug-895025-fixed
 * version at startup.  This will eventually be removed when bug 895025
 * get fixed in Firefox release channel.
 */

"use strict";

////////////////////////////////////////////////////////////////////////////////
//// Globals

const Cc = Components.classes;
const Ci = Components.interfaces;
const Cu = Components.utils;
const Cr = Components.results;

Cu.import("resource://gre/modules/XPCOMUtils.jsm");

/**
 * CID and Contract ID of bug-895025-fixed version of IEProfileMigrator.
 */
const kIEProfileMigratorCid = Components.ID("{553aa4ca-cc8c-419e-8ee6-2a68cd7c64a6}");
const kIEProfileMigratorContractId = "@mozilla.org/profile/migrator;1?app=browser&type=ie";

////////////////////////////////////////////////////////////////////////////////
//// MigrationStartup

function MigrationStartup() { }

MigrationStartup.prototype = {
  classID: Components.ID("{f235e4f0-d3c1-4c84-a547-343eaa146859}"),

  _xpcom_factory: XPCOMUtils.generateSingletonFactory(MigrationStartup),

  //////////////////////////////////////////////////////////////////////////////
  //// nsISupports

  QueryInterface: XPCOMUtils.generateQI([Ci.nsIObserver]),

  //////////////////////////////////////////////////////////////////////////////
  //// nsIObserver

  observe: function DS_observe(aSubject, aTopic, aData)
  {
    if (aTopic != "xpcom-startup") {
      Cu.reportError("Unexpected observer notification.");
      return;
    }

    // Override original IEProfileMigrator implementation with bug-895025-fixed version.
    // This must be done at application startup and not in the manifest to
    // ensure that our version overrides the original one.
    Components.manager.QueryInterface(Ci.nsIComponentRegistrar)
                      .registerFactory(kIEProfileMigratorCid, "",
                                       kIEProfileMigratorContractId, null);
  },
};

////////////////////////////////////////////////////////////////////////////////
//// Module

this.NSGetFactory = XPCOMUtils.generateNSGetFactory([MigrationStartup]);
